<template>
  <h1>El-表单组件</h1>
  <el-form style="width: 600px;margin: 0 auto;" label-width="80px">
    <el-form-item label="用户名">
      <el-input placeholder="请输入用户名" v-model="user.username"></el-input>
    </el-form-item>
    <el-form-item label="密码">
      <el-input placeholder="请输入密码" show-password v-model="user.password"></el-input>
    </el-form-item>
    <el-form-item label="性别">
      <el-radio-group v-model="user.gender">
        <el-radio label="男" value="1"></el-radio>
        <el-radio label="女" value="0"></el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="所在地">
      <el-select placeholder="请选择" v-model="user.city">
        <el-option label="上海" value="上海"></el-option>
        <el-option label="北京" value="北京"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="管理员">
      <el-switch v-model="user.isAdmin"></el-switch>
    </el-form-item>
    <el-form-item>
      <el-button type="success" @click="reg">点我提交</el-button>
    </el-form-item>
    <hr>
    <p v-if="isShow">一袋米要抗几楼</p>
    <p v-else="isShow">莫使金樽空对月</p>
    <button @click="changeStatus">点我切换p标签的显示状态</button>
    <hr>
    <input type="text" placeholder="请在此处粘贴要展示的图片路径" v-model="imgUrl">
    <img :src="imgUrl" alt="无效的链接">
    <hr>
    <ul>
      <li v-for="(item,index) in proArr">
        {{item}}
        <el-button type="danger" @click="del(index)">删除</el-button>
      </li>
    </ul>

  </el-form>
</template>

<script setup>
import {ref} from "vue";

//定义对象用来保存表单数据
const user = ref({
  username: '',
  password: '',
  gender: '',
  city: '',
  isAdmin: false
});

// 定义变量控制p标签显示状态
const isShow = ref(true);
// 定义切换状态的方法
const changeStatus = () => {
  isShow.value = !isShow.value;
}

//定义注册用户的方法
const reg = () => {
  console.log(user.value);
}

const imgUrl = ref('');
const proArr = ref(['苹果','香蕉','橘子','葡萄','西瓜']);
const del = (index) => {
  proArr.value.splice(index,1);
}


</script>

<style scoped>

</style>